<?php
/**
 * Created by VIM.
 * User: Administrator
 * Date: 13-9-8
 * Time: 下午11:33
 */

class Adminarticle extends CI_Controller
{
    function index()
    {
        $this->load->model("Article_pro");
        $data = $this->Article_pro->list_properties();
        $this->load->library("form_validation");
        $this->load->helper("url");
        $result["cc"] = $data->result();
        header("Content-type:text/html;charset=utf-8");
        $this->load->view("headernone", $result);
        $this->load->view("/admin/article");
    }


    function add()
    {
        /**
         * add data to databases
         */
        $this->load->helper("url");
        $this->load->library("form_validation");
        $this->form_validation->set_rules("name", "article name is Null", "required");
        $this->form_validation->set_rules("description", "description is null", "required");
        if($this->form_validation->run()===TRUE)
        {
           $this->load->model("Article_pro"); 
           $data = $this->Article_pro->add();
           if($data===TRUE){
               $result  = array("code"=>0, "msg"=>"insert data success");
               echo json_encode($result);
           }
        }else{
            echo "article or description can't be null";   
        }        
    }

    function update(){
        $this->load->model("Article_pro"); 

        $data = $this->Article_pro->update();
        if($data===TRUE){
           $result = array("code"=>0, "msg"=>"update data success"); 
           echo json_encode($result);
        }else{
            echo "update date failture";
        }
    }
    
    function delete(){
        $this->load->model("Article_pro"); 

        $data = $this->Article_pro->deletes();
        if($data===TRUE){
           $result = array("code"=>0, "msg"=>"update data success"); 
           echo json_encode($result);
        }else{
            echo "update date failture";
        }
    }
/*
    function list()
    {
        /**
         * get all properties
    }
 */
}
